<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //对象的属性值是对象
        var user={
            name:{
                firstName:"王",
                lastName:"子伟"
            },
            age:20
        };

        console.log("免贵姓:"+user.name.firstName);
        console.log("免贵姓:"+user["name"].firstName);
        console.log("免贵姓:"+user["name"]["firstName"]);
        console.log("免贵姓:"+user.name["firstName"]);

        var user2={
            name:"alice",
            hobbies:["吃饭","睡觉","打游戏"]
        };
        console.log(user2.hobbies[0],user2.hobbies[1],user2.hobbies[2]);
        for(var i=0;i<user2.hobbies.length;i++){
            console.log(user2.hobbies[i]);
        }


        //数组中存放了三个对象
        var arrs=[
            {username:"alice1",age:20},
            {username:"alice2",age:40},
            {username:"alice3",age:30}
        ];

        //使用for循环循环遍历数组
        // for(var i=0;i<arrs.length;i++){
        //     // console.log(arrs[i]);//单个对象
        //     console.log(arrs[i].username+","+arrs[i].age);
        // }

        //使用for...in循环来遍历数组
        for(var index in arrs){
            // console.log(index);//索引
            // console.log(arrs[index]);//单个对象
            console.log(arrs[index].username+","+arrs[index].age);
        }


        // var user3={
        //     name:"刘璐",
        //     hobbies:[
        //         {hobby:"贴膜"},
        //         {hobby:"打游戏"},
        //         {hobby:"唱歌"}
        //     ]
        // };
        // console.log(user3.hobbies[1].hobby);
        // for(var i=0;i<user3.hobbies.length;i++){
        //     console.log(user3.hobbies[i].hobby);
        // }
    </script>
</head>
<body>
    
</body>
</html>